package algorithm;

/**
 * 100. 相同的树
 * @author Panbo Guo
 * @date 2021/7/15
 */
public class T00100 {

    public static void main(String[] args) {
        Integer[] arr1 = new Integer[]{1,2};
        Integer[] arr2 = new Integer[]{1,null,2};
        System.out.println(new Solution().isSameTree(TreeUtils.buildTree(arr1), TreeUtils.buildTree(arr2)));
    }

    static class Solution {
        public boolean isSameTree(TreeNode p, TreeNode q) {
            if (p == null)
                return q == null;
            if (q == null)
                return false;

            return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }
}
